
class Solution
{
public:
        ListNode* removeZeroSumSublists(ListNode* head)
        {
            int prefix = 0;
            ListNode* newHead = new ListNode(0, head);
            unordered_map<int, ListNode*> sumMap;
            for(ListNode* now = newHead; now; now = now->next)
            {
                prefix+=now->val;
                sumMap[prefix] = now;
            }
            prefix = 0;
            for(ListNode* now = newHead; now; now = now->next)
            {
                prefix += now->val;
                if(sumMap[prefix]!=now)
                {
                    ListNode* newTail = sumMap[prefix]->next;
                    //需要进行销毁中间数据
                    ListNode* del = now->next;
                    while(del!=newTail)
                    {
                        ListNode* dd = del;
                        del = del->next;
                        delete dd;
                    }
                    //到此处理完毕，将剩下链表拼接起来继续下一次for循环
                    now->next = newTail;
                }
            }
            //delete newHead;
            ListNode* ret = newHead->next;
            delete newHead;
            return ret;
        }
};

int main()
{
